package com.designpatterns.creational.singleton;

/**
 * 双重校验锁 DCL
 * 线程安全
 * 描述：这种方式采用双锁机制，安全且在多线程情况下能保持高性能。
 *      getInstance() 的性能对应用程序很关键。
 */
public class SingletonDCL {
    private volatile static SingletonDCL singletonDCL;

    public static SingletonDCL getInstance() {
        if (singletonDCL == null) {
            synchronized (SingletonDCL.class) {
                if (singletonDCL == null) {
                    singletonDCL = new SingletonDCL();
                }
            }
        }

        return singletonDCL;
    }

    public void showMessage() {
        System.out.println("Hello World" + this);
    }
}
